package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.interfaces.IModifyPoneView;
import com.global.college.utils.RxTimer;


/**
 * 修改密码
 */
public class ModifyPhonePresenter extends BasePresenter {

    private IModifyPoneView mIModifyPoneView;
    private RxTimer rxTimer;
    private boolean isVisible = true;
    public ModifyPhonePresenter(Context context) {
        super(context);
    }

    public void setModifyPoneView(IModifyPoneView modifyPoneView) {
        mIModifyPoneView = modifyPoneView;
    }


    /**
     * 获取验证码
     *
     * @param
     */
    public void getSmsCode(String phone) {
        mAuthRequestClient.getSmsCode(phone).subscribe(new ProgressSubscriber<Object>(mContext, true) {
            @Override
            public void onNext(Object smsModel) {
                if (null != mIModifyPoneView) {
                    mIModifyPoneView.onGetSmsCodeSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIModifyPoneView){
                    mIModifyPoneView.onGetSmsCodeFail(e.getMessage());
                }
            }
        });
    }


    /**
     * 修改手机号
     *
     * @param
     */
    public void editPone(String phone,String code,String userName) {
        mAuthRequestClient.editPhone(phone, code,userName).subscribe(new ProgressSubscriber<Object>(mContext, true) {
            @Override
            public void onNext(Object object) {
                if (null != mIModifyPoneView) {
                    mIModifyPoneView.editPhoneSuccess(object);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mIModifyPoneView.editPhoneFail(e.getMessage());
            }
        });
    }
}
